package Controllers;

import Entities.Book;
import Facades.BookFacade;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean(name = "bookController")
@ViewScoped
public class BookController extends AbstractController<Book> implements Serializable {

    @EJB
    private BookFacade ejbFacade;

    public BookController() {
        super(Book.class);
    }

    @PostConstruct
    public void init() {
        super.setFacade(ejbFacade);
    }

    @Override
    protected void setEmbeddableKeys() {
        this.getSelected().getBookPK().setKnowledgeAreaidknowledgeArea(this.getSelected().getKnowledgeArea().getIdknowledgeArea());
        this.getSelected().getBookPK().setEditorialidEditorial(this.getSelected().getEditorial().getIdEditorial());
        this.getSelected().getBookPK().setBookTypeidbookType(this.getSelected().getBookType().getIdbookType());
    }

    @Override
    protected void initializeEmbeddableKey() {
        this.getSelected().setBookPK(new Entities.BookPK());
    }
}
